export type rows = {
  id: string
  expensesType: number
  content: string
  remark: string
  estimatedAmount: string
  planStartTime: string
  planFinishTime: string
  status: number
}

export type countRows = {
  id: string
  expensesType: number
  content: string
  remark: string
  estimatedAmount: string
  planStartTime: string
  planFinishTime: string
  status: number
  realAmount: string
  realTime: string
}

export type accountRows = {
  id: string
  countId: string
  content: string
  remark: string
  startTime: string
  endTime: string
  accountType: number
  accountNo: string
  password: string
  dateTime: string[]
  address: string
}

export type queryCondition = {
  dateTime: string[]
  startTime: string
  endTime: string
  expensesType: number
}

import request from './request'

export function addPlan(data: rows) {
  return request({
    url: 'expenses/plan/add',
    method: 'post',
    data: data,
  })
}

export function queryPlan(data: queryCondition) {
  if (data.dateTime) {
    const startTime = data.dateTime[0]
    const endTime = data.dateTime[1]
    data.startTime = startTime
    data.endTime = endTime
  }
  return request({
    url: 'expenses/plan/query',
    method: 'post',
    data: data,
  })
}

export function editPlan(data: rows) {
  return request({
    url: 'expenses/plan/edit',
    method: 'post',
    data: data,
  })
}

export function deletePlan(data: string) {
  return request({
    url: 'expenses/plan/delete?id=' + data,
    method: 'delete',
    data: data,
  })
}

export function finishIt(data: string) {
  return request({
    url: 'expenses/plan/finish',
    method: 'post',
    data: data,
  })
}

export function queryCount(data: queryCondition) {
  if (data.dateTime) {
    const startTime = data.dateTime[0]
    const endTime = data.dateTime[1]
    data.startTime = startTime
    data.endTime = endTime
  }
  return request({
    url: 'expenses/count/query',
    method: 'post',
    data: data,
  })
}

export function noPlanExpenses(data: countRows) {
  return request({
    url: 'expenses/count/noPlanExpenses',
    method: 'post',
    data: data,
  })
}

export function editCount(data: any) {
  console.log('edit:' + JSON.stringify(data))
  return request({
    url: 'expenses/count/update',
    method: 'post',
    data: data,
  })
}

export function deleteCountInfo(data: string) {
  return request({
    url: 'expenses/count/delete?id=' + data,
    method: 'delete',
    data: data,
  })
}

export function memberAdd(data: accountRows) {
  console.log('memberAdd:' + JSON.stringify(data))
  return request({
    url: 'member/add',
    method: 'post',
    data: data,
  })
}

export function memberGetOne(data: any) {
  return request({
    url: 'member/queryOne?countId=' + data,
    method: 'get',
  })
}

export function memberQueryList(data: any) {
  if (data.dateTime) {
    const startTime = data.dateTime[0]
    const endTime = data.dateTime[1]
    data.startTime = startTime
    data.endTime = endTime
  }

  return request({
    url: 'member/queryList',
    method: 'post',
    data: data,
  })
}

export function memberDelete(data: any) {
  return request({
    url: 'member/delete?id=' + data,
    method: 'delete',
  })
}
